package com.lwb.demo1.controller;

import com.alibaba.fastjson.JSON;
import com.lwb.demo.entity.DemoEntity;
import com.lwb.demo1.service.Demo1Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/test")
public class TestController {

    @Resource
    Demo1Service demo1Service;

    @RequestMapping("/select/{id}")
    public String select(@PathVariable("id") String id) {
        try {
            List<DemoEntity> list = demo1Service.selectById(id);
            return JSON.toJSONString(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    @RequestMapping("/save/{id}")
    public String save(@PathVariable("id") String id) {
        try {
            demo1Service.save(id);
        } catch (Exception e) {
            e.printStackTrace();
            return id + " save fail!";
        }
        return id + " save success!";
    }
}
